@extends("layouts.backend.webadmin")
@section('page-header')
    <h1>
        <small>falw\menu</small>
    </h1>
@endsection

@section('content')
    <style>
        #cate_id{
            width:100%;}
    </style>
    <link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
    <link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2totree.css">
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        @if($errors->any())
                            <ul class="alert alert-danger">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        @endif
                        @if($action =='add')
                            <form action="{{ URL::route('admin.goods.goodscateadd') }}" method="POST">
                            @elseif($action =='update')
                            <form action="{{ URL::route('admin.goods.goodscateupdate') }}" method="POST">
                            <input type="hidden" name="id" value="{{$item->id}}">
                            @endif
                            <div class="form-group">
                                <label for="picture">分类名称</label>
                                <input type="text" class="form-control" id="name" placeholder="分类名称"
                                       name="name"
                                       @if($action =='update')value="{{$item->name}} @else value="{{old('name')}}" @endif">
                            </div>
                            <div class="form-group">
                                <label for="pid">父级分类</label>
                                <select class="form-control select2"   id="pid" name="pid">
                                <option class="l1 non-leaf" value="0">所有</option>
                                @foreach($gclist as $category)
                                    <option class="l{{$category->num+1}} {{$category->child=='yes'?'non-leaf':''}}" data-pup="{{$category->pid}}" value="{{$category->id}}"  @if(($action =='update' || $action =='detail') && $category->id == $item->pid) selected @endif >{{$category->name}}</option>
                                @endforeach
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="description">描述</label>
                                <input type="text" class="form-control" id="description" placeholder="描述" name="description" @if($action =='update')value="{{$item->description}}" @else value="{{old('description')}}" @endif>
                            </div>
                            {!! csrf_field() !!}
                            @if($action =='add')
                                <button type="submit" class="btn btn-default">添加</button>
                            @else
                                <button type="submit" class="btn btn-default">更新</button>
                            @endif
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
@stop
@section('javascript-end')
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2totree.js"></script>
    <script>
        $(function(){
            $('#pid').select2ToTree({"border-radius":'0px'});
        });
    </script>
@endsection